﻿using BaseUI;
using BLL;
using Model;
using Newtonsoft.Json.Linq;
using System;
using System.Data;
using System.Web.UI;
using Thksoft.UserCotrols;
using Utility.Helper;

namespace Thksoft.Module.DataDetail
{
    public partial class ProjectFundDetail_Year : BasePage
    {
        private static bool IsSelect = false;
        public DataTable dtYear;
        public decimal planappId;
        public string cmyName, myDate, valTime, valUser, busId, year;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.Params["Type"] == "API")
                {
                    var requsetData = AjaxResult.GetPostData(this.Context);
                    //区别抓包
                    switch (requsetData["Type"].ToObject<int>())
                    {
                        case 0:
                            {
                                #region 资金计划总表

                                var data = new JObject();
                                var year = requsetData["Year"].ToObject<int>();
                                var companyId = requsetData["CompanyId"].ToObject<int>();
                                var bll = new QS_PLANYEARAPPLYBLL();
                                var _data = bll.GetData_11(companyId, year);
                                data["Data"] = JToken.FromObject(_data);
                                AjaxResult.Success(this.Context, data);
                                return;

                                #endregion 资金计划总表
                            }
                        case 1:
                            {
                                #region 主营业务收入

                                var data = new JObject();
                                var year = requsetData["Year"].ToObject<int>();
                                var companyId = requsetData["CompanyId"].ToObject<int>();
                                var bll = new QS_PLANYEARAPPLYBLL();
                                var _data = bll.GetData_22(companyId, year);
                                data["Data"] = JToken.FromObject(_data);
                                AjaxResult.Success(this.Context, data);
                                return;

                                #endregion 主营业务收入
                            }
                        case 2:
                            {
                                #region 天燃气购入

                                var data = new JObject();
                                var year = requsetData["Year"].ToObject<int>();
                                var companyId = requsetData["CompanyId"].ToObject<int>();
                                var bll = new QS_PLANYEARAPPLYBLL();
                                var _data = bll.GetData_33(companyId, year);
                                data["Data"] = JToken.FromObject(_data);
                                AjaxResult.Success(this.Context, data);
                                return;

                                #endregion 天燃气购入
                            }
                        case 3:
                            {
                                #region 安装外包费用

                                var data = new JObject();
                                var year = requsetData["Year"].ToObject<int>();
                                var companyId = requsetData["CompanyId"].ToObject<int>();
                                var bll = new QS_PLANYEARAPPLYBLL();
                                var _data = bll.GetData_44(companyId, year, 1);
                                data["Data"] = JToken.FromObject(_data);
                                AjaxResult.Success(this.Context, data);
                                return;

                                #endregion 安装外包费用
                            }
                        case 4:
                            {
                                #region 材料费用

                                var data = new JObject();
                                var year = requsetData["Year"].ToObject<int>();
                                var companyId = requsetData["CompanyId"].ToObject<int>();
                                var bll = new QS_PLANYEARAPPLYBLL();
                                var _data = bll.GetData_44(companyId, year, 2);
                                data["Data"] = JToken.FromObject(_data);
                                AjaxResult.Success(this.Context, data);
                                return;

                                #endregion 材料费用
                            }
                        case 5:
                            {
                                #region 大修费用

                                var data = new JObject();
                                var year = requsetData["Year"].ToObject<int>();
                                var companyId = requsetData["CompanyId"].ToObject<int>();
                                var bll = new QS_PLANYEARAPPLYBLL();
                                var _data = bll.GetData_44(companyId, year, 3);
                                data["Data"] = JToken.FromObject(_data);
                                AjaxResult.Success(this.Context, data);
                                return;

                                #endregion 大修费用
                            }
                        case 6:
                            {
                                #region 城市管网项目

                                var data = new JObject();
                                var year = requsetData["Year"].ToObject<int>();
                                var companyId = requsetData["CompanyId"].ToObject<int>();
                                var bll = new QS_PLANYEARAPPLYBLL();
                                var _data = bll.GetData_44(companyId, year, 4);
                                data["Data"] = JToken.FromObject(_data);
                                AjaxResult.Success(this.Context, data);
                                return;

                                #endregion 城市管网项目
                            }
                        default:
                            AjaxResult.Reson(this.Context, 0, null, string.Format("（{0}）API接不存在", requsetData["Type"].ToObject<int>()));
                            break;
                    }

                    return;
                }

                FORM_DATE.Value = DateTime.Now.ToString("yyyy");
                BindDt();
                BindData();
            }
        }

        /// <summary>
        /// 页面关联
        /// </summary>
        public void BindData()
        {
            #region 附表加载

            Control TabPanel0 = Page.LoadControl("../../UserCotrols/PlanDetailSum_Year.ascx");
            PlaceHolder0.Controls.Add(TabPanel0);

            Control TabPanel1 = Page.LoadControl("../../UserCotrols/PlanDetailOne_Year.ascx");
            PlaceHolder1.Controls.Add(TabPanel1);

            Control TabPanel2 = Page.LoadControl("../../UserCotrols/PlanDetailTwo_Year.ascx");
            PlaceHolder2.Controls.Add(TabPanel2);

            PlanDetailThree_Year TabPanel3 = Page.LoadControl("../../UserCotrols/PlanDetailThree_Year.ascx") as PlanDetailThree_Year;
            PlaceHolder3.Controls.Add(TabPanel3);
            TabPanel3.proType = 1;
            TabPanel3.BindData();

            PlanDetailThree_Year TabPanel4 = Page.LoadControl("../../UserCotrols/PlanDetailThree_Year.ascx") as PlanDetailThree_Year;
            PlaceHolder4.Controls.Add(TabPanel4);
            TabPanel4.proType = 2;
            TabPanel4.BindData();

            PlanDetailSix_Year TabPanel5 = Page.LoadControl("../../UserCotrols/PlanDetailSix_Year.ascx") as PlanDetailSix_Year;
            PlaceHolder5.Controls.Add(TabPanel5);
            TabPanel5.proType = 3;
            TabPanel5.BindData();

            PlanDetailSix_Year TabPanel6 = Page.LoadControl("../../UserCotrols/PlanDetailSix_Year.ascx") as PlanDetailSix_Year;
            TabPanel6.proType = 4;
            PlaceHolder6.Controls.Add(TabPanel6);
            TabPanel6.BindData();

            #endregion 附表加载
        }

        /// <summary>
        /// 条件查询
        /// </summary>
        public void BindDt()
        {
            #region 初始条件

            var cmyId = FORM_COMPANY_ID.Value;
            try
            {
                year = FORM_DATE.Value.ToString();
            }
            catch (Exception)
            {
                MessageBox.Show(this, "【系统提示】输入参数异常！");
                return;
            }

            #endregion 初始条件

            string sql = string.Format(@" select * from qx_planyearapply t where t.N_BUSINESS_STATE NOT IN (0,-1) and t.N_YEAR=" + year + " and t.N_COMPANY_ID=" + cmyId);
            dtYear = new BaseBLL().Query(sql);

            if (dtYear != null && dtYear.Rows.Count > 0)
            {
                planappId = Convert.ToDecimal(dtYear.Rows[0]["N_YEARAPP_ID"]);
                var user = new Sys_CompanyBLL().GetInfoById(cmyId.ToString());
                if (user != null)
                {
                    cmyName = user.CMY_NAME;
                }

                busId = dtYear.Rows[0]["N_BUSINESS_ID"].ToString();

                QS_Business bModel = new Qs_BusinessBLL().GetBusinessById(Decimal.Parse(busId));
                if (bModel != null)
                {
                    myDate = bModel.Business_operator_date.ToString("yyyy");

                    valUser = new Sys_UserBLL().GetInfoById(bModel.Business_operator_Id.ToString()).USER_NAME;
                }
                year = dtYear.Rows[0]["N_YEAR"].ToString();

                IsSelect = true;
            }
            else
            {
                IsSelect = false;
                MessageBox.Show(this, "【系统提示】没有查询到相关数据！");
                return;
            }
        }

        protected void btnSelect_Click(object sender, EventArgs e)
        {
            BindDt();
            BindData();
        }

        /// <summary>
        /// 导出
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnDaochu_Click(object sender, EventArgs e)
        {
            DataSet ds = new DataSet();

            btnSelect_Click(sender, e);

            if (!IsSelect)
            {
                MessageBox.Show(Page, "【系统提示】未能查询出数据，暂时不能导出。");
                return;
            }

            PlanDetailSum_Year TabPanel0 = PlaceHolder0.Controls[0] as PlanDetailSum_Year;
            TabPanel0.BindDaodu();
            var dt0 = TabPanel0.dt;
            Classification(ds, dt0, "年资金计划申请表");

            PlanDetailOne_Year TabPanel1 = PlaceHolder1.Controls[0] as PlanDetailOne_Year;
            TabPanel1.btnDaochu_Click();
            var dt1 = TabPanel1.dt;
            Classification(ds, dt1, "主营业务收入年明细表");

            PlanDetailTwo_Year TabPanel2 = PlaceHolder2.Controls[0] as PlanDetailTwo_Year;
            TabPanel2.BindDaodu();
            var dt2 = TabPanel2.dt;
            Classification(ds, dt2, "天然气购入年明细表");

            PlanDetailThree_Year TabPanel3 = PlaceHolder3.Controls[0] as PlanDetailThree_Year;
            TabPanel3.proType = 1;
            TabPanel3.BindData();
            TabPanel3.BindDaodu();
            var dt3 = TabPanel3.dt;
            Classification(ds, dt3, "安装外包费用年明细表");

            PlanDetailThree_Year TabPanel4 = PlaceHolder4.Controls[0] as PlanDetailThree_Year;
            TabPanel4.proType = 2;
            TabPanel4.BindData();
            TabPanel4.BindDaodu();
            var dt4 = TabPanel4.dt;
            Classification(ds, dt4, "材料费用年明细表");

            PlanDetailSix_Year TabPanel5 = PlaceHolder5.Controls[0] as PlanDetailSix_Year;
            TabPanel5.proType = 3;
            TabPanel5.BindData();
            TabPanel5.BindDaodu();
            var dt5 = TabPanel5.dt;
            Classification(ds, dt5, "大修费用年明细表");

            PlanDetailSix_Year TabPanel6 = PlaceHolder6.Controls[0] as PlanDetailSix_Year;
            TabPanel6.BindDaodu();
            TabPanel6.proType = 4;
            var dt6 = TabPanel6.dt;
            Classification(ds, dt6, "城市管网项目年明细表");

            ds.ExportByWeb(null, "年资金计划申请表（" + myDate + "）.xls");
        }

        /// <summary>
        /// 打印
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnPrint_Click(object sender, EventArgs e)
        {
            switch (TabContainer1.ActiveTabIndex)
            {
                case 0:
                    {
                        PlanDetailSum_Year TabPanel0 = PlaceHolder0.Controls[0] as PlanDetailSum_Year;
                        TabPanel0.BindPrint();
                    }
                    break;

                case 1:
                    {
                        PlanDetailOne_Year TabPanel1 = PlaceHolder1.Controls[0] as PlanDetailOne_Year;
                        TabPanel1.btnPrint_Click();
                    }
                    break;

                case 2:
                    {
                        PlanDetailTwo_Year TabPanel2 = PlaceHolder2.Controls[0] as PlanDetailTwo_Year;
                        TabPanel2.BindPrint();
                    }
                    break;

                case 3:
                    {
                        PlanDetailThree_Year TabPanel3 = PlaceHolder3.Controls[0] as PlanDetailThree_Year;
                        TabPanel3.proType = 1;
                        TabPanel3.BindData();
                        TabPanel3.BindPrint();
                    }
                    break;

                case 4:
                    {
                        PlanDetailThree_Year TabPanel4 = PlaceHolder4.Controls[0] as PlanDetailThree_Year;
                        TabPanel4.proType = 2;
                        TabPanel4.BindData();
                        TabPanel4.BindPrint();
                    }
                    break;

                case 5:
                    {
                        PlanDetailSix_Year TabPanel5 = PlaceHolder5.Controls[0] as PlanDetailSix_Year;
                        TabPanel5.proType = 3;
                        TabPanel5.BindData();
                        TabPanel5.BindPrint();
                    }
                    break;

                case 6:
                    {
                        PlanDetailSix_Year TabPanel6 = PlaceHolder6.Controls[0] as PlanDetailSix_Year;
                        TabPanel6.proType = 4;
                        TabPanel6.BindData();
                        TabPanel6.BindPrint();
                    }
                    break;

                default:
                    break;
            }
        }

        /// <summary>
        /// 将DataTable里面的数据按 type 规则分为一定数量的DataTable 放到DataSet里
        /// </summary>
        /// <param name="ds">目标存储</param>
        /// <param name="dt">源数据</param>
        /// <param name="type">规则类型</param>
        private void Classification(DataSet ds, DataTable dt, string type)
        {
            if (type == "年资金计划申请表")
            {
                DataTable table = new DataTable();
                table = dt.Clone();
                table.TableName = "年资金计划申请表";
                ds.Tables.Add(table);

                ds.Tables[0].Columns["n_proid"].ColumnName = "编号";
                ds.Tables[0].Columns["c_proname"].ColumnName = "项目名称";
                ds.Tables[0].Columns["n_amount"].ColumnName = "计划审核资金";
                ds.Tables[0].Columns["N_AMOUNT_WEEK"].ColumnName = "年度各周审核资金";
                ds.Tables[0].Columns["N_USEAMOUNT_WEEK"].ColumnName = "已支付金额";
                ds.Tables[0].Columns["N_AMOUNTPROBABILITY"].ColumnName = "流出（入）率";
                ds.Tables[0].Columns["c_remark"].ColumnName = "备注";
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    ds.Tables[0].Rows.Add(dt.Rows[i].ItemArray);
                }
                //ds.Tables[0].Columns.Remove(ds.Tables[0].Columns["IF_DETAILS"]);
                //ds.Tables[0].Columns.Remove(ds.Tables[0].Columns["DETAILS_CODE"]);
                //ds.Tables[0].Columns.Remove(ds.Tables[0].Columns["n_type"]);
                //ds.Tables[0].Columns.Remove(ds.Tables[0].Columns["n_mdetail_id"]);
                //ds.Tables[0].Columns.Remove(ds.Tables[0].Columns["n_monthapp_id"]);
                //ds.Tables[0].Columns.Remove(ds.Tables[0].Columns["n_amount2"]);
                //ds.Tables[0].Columns.Remove(ds.Tables[0].Columns["c_remark"]);
                //ds.Tables[0].Columns.Remove(ds.Tables[0].Columns["N_PARENTID"]);
                //ds.Tables[0].Columns.Remove(ds.Tables[0].Columns["N_NUM1"]);
                //ds.Tables[0].Columns.Remove(ds.Tables[0].Columns["N_NUM2"]);
            }
            if (type == "主营业务收入年明细表")
            {
                DataTable table = new DataTable();
                table = dt.Clone();
                table.TableName = "主营业务收入年明细表";
                ds.Tables.Add(table);

                ds.Tables[1].Columns["R"].ColumnName = "序号";
                ds.Tables[1].Columns["C_PRONAME"].ColumnName = "收入类别";
                ds.Tables[1].Columns["N_AMOUNT"].ColumnName = "预收气款金额";
                ds.Tables[1].Columns["N_WEEK_AMOUNT"].ColumnName = "周累计已审批金额";
                ds.Tables[1].Columns["N_WEEK_USEAMOUNT"].ColumnName = "周累计已支付金额";
                ds.Tables[1].Columns["N_GOL"].ColumnName = "流入率";
                ds.Tables[1].Columns["C_REMARK"].ColumnName = "备注";
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    ds.Tables[1].Rows.Add(dt.Rows[i].ItemArray);
                }
                ds.Tables[1].Columns.Remove(ds.Tables[1].Columns["N_ID1"]);
                ds.Tables[1].Columns.Remove(ds.Tables[1].Columns["N_PRO_ID"]);
                //ds.Tables[1].Columns.Remove(ds.Tables[1].Columns["N_TYPE"]);
                ds.Tables[1].Columns.Remove(ds.Tables[1].Columns["N_PLANAPP_ID"]);
                //ds.Tables[1].Columns.Remove(ds.Tables[1].Columns["N_NUM"]);
                //ds.Tables[1].Columns.Remove(ds.Tables[1].Columns["PRONAME"]);

                //ds.Tables[1].Columns.Remove(ds.Tables[1].Columns["N_DOSAGE"]);
                //ds.Tables[1].Columns.Remove(ds.Tables[1].Columns["N_PRICE"]);
                //ds.Tables[1].Columns.Remove(ds.Tables[1].Columns["C_BANK"]);
            }
            if (type == "天然气购入年明细表")
            {
                DataTable table = new DataTable();
                table = dt.Clone();
                table.TableName = "天然气购入年明细表";
                ds.Tables.Add(table);

                ds.Tables[2].Columns["r"].ColumnName = "序号";
                ds.Tables[2].Columns["C_CUSTOMER_NAME"].ColumnName = "单位名称";
                ds.Tables[2].Columns["C_USER_TYPE"].ColumnName = "用户类别";
                ds.Tables[2].Columns["N_AMOUNT"].ColumnName = "预付气款金额";
                ds.Tables[2].Columns["N_WEEK_AMOUNT"].ColumnName = "周累计已审批金额";
                ds.Tables[2].Columns["N_WEEK_USEAMOUNT"].ColumnName = "周累计已支付金额";
                ds.Tables[2].Columns["N_GOL"].ColumnName = "流出率";
                ds.Tables[2].Columns["C_REMARK"].ColumnName = "备注";
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    ds.Tables[2].Rows.Add(dt.Rows[i].ItemArray);
                }
                ds.Tables[2].Columns.Remove(ds.Tables[2].Columns["N_ID2"]);
                ds.Tables[2].Columns.Remove(ds.Tables[2].Columns["N_PRO_ID"]);
                //ds.Tables[2].Columns.Remove(ds.Tables[2].Columns["N_TYPE"]);
                ds.Tables[2].Columns.Remove(ds.Tables[2].Columns["N_PLANAPP_ID"]);
                //ds.Tables[2].Columns.Remove(ds.Tables[2].Columns["N_CUSTOMER_ID"]);
                //ds.Tables[2].Columns.Remove(ds.Tables[2].Columns["N_NUM"]);
                //ds.Tables[2].Columns.Remove(ds.Tables[2].Columns["R"]);

                //ds.Tables[2].Columns.Remove(ds.Tables[2].Columns["N_DOSAGE"]);
                //ds.Tables[2].Columns.Remove(ds.Tables[2].Columns["N_PRICE"]);
                //ds.Tables[2].Columns.Remove(ds.Tables[2].Columns["C_BANK"]);
            }
            if (type == "安装外包费用年明细表")
            {
                DataTable table = new DataTable();
                table = dt.Clone();
                table.TableName = "安装外包费用年明细表";
                ds.Tables.Add(table);

                ds.Tables[3].Columns["r"].ColumnName = "序号";
                ds.Tables[3].Columns["C_CUSTOMER_NAME"].ColumnName = "单位名称";
                ds.Tables[3].Columns["N_GZAMOUNT"].ColumnName = "账面应付余额";
                ds.Tables[3].Columns["N_WEEK_AMOUNT"].ColumnName = "周累计审批金额";
                ds.Tables[3].Columns["N_WEEK_USEAMOUNT"].ColumnName = "周累计已支付金额";
                ds.Tables[3].Columns["N_GOL"].ColumnName = "流出率";
                ds.Tables[3].Columns["C_REMARK"].ColumnName = "备注";
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    ds.Tables[3].Rows.Add(dt.Rows[i].ItemArray);
                }
                ds.Tables[3].Columns.Remove(ds.Tables[3].Columns["N_ID3"]);
                ds.Tables[3].Columns.Remove(ds.Tables[3].Columns["N_PRO_ID"]);
                //ds.Tables[3].Columns.Remove(ds.Tables[3].Columns["N_TYPE"]);
                ds.Tables[3].Columns.Remove(ds.Tables[3].Columns["N_PLANAPP_ID"]);
                //ds.Tables[3].Columns.Remove(ds.Tables[3].Columns["N_CUSTOMER_ID"]);
                ds.Tables[3].Columns.Remove(ds.Tables[3].Columns["N_PROTYPE"]);
                //ds.Tables[3].Columns.Remove(ds.Tables[3].Columns["C_PRONAME"]);
                //ds.Tables[3].Columns.Remove(ds.Tables[3].Columns["N_NUM"]);
                //ds.Tables[3].Columns.Remove(ds.Tables[3].Columns["N_MONTHJEUSE"]);
                ////ds.Tables[3].Columns.Remove(ds.Tables[3].Columns["N_REAMOUNT"]);

                //ds.Tables[3].Columns.Remove(ds.Tables[3].Columns["C_AMOUT_TYPE"]);
                //ds.Tables[3].Columns.Remove(ds.Tables[3].Columns["C_AMOUT_USE"]);
                //ds.Tables[3].Columns.Remove(ds.Tables[3].Columns["N_ZBAMOUNT"]);
                //ds.Tables[3].Columns.Remove(ds.Tables[3].Columns["N_LASTMONTHJEUSE"]);
                //ds.Tables[3].Columns.Remove(ds.Tables[3].Columns["N_SPAMOUNT1"]);
                //ds.Tables[3].Columns.Remove(ds.Tables[3].Columns["N_SPAMOUNT2"]);
                //ds.Tables[3].Columns.Remove(ds.Tables[3].Columns["C_BANK"]);
            }
            if (type == "材料费用年明细表")
            {
                DataTable table = new DataTable();
                table = dt.Clone();
                table.TableName = "材料费用年明细表";
                ds.Tables.Add(table);

                ds.Tables[4].Columns["r"].ColumnName = "序号";
                ds.Tables[4].Columns["C_CUSTOMER_NAME"].ColumnName = "单位名称";
                ds.Tables[4].Columns["N_GZAMOUNT"].ColumnName = "账面应付余额";
                ds.Tables[4].Columns["N_WEEK_AMOUNT"].ColumnName = "周累计审批金额";
                ds.Tables[4].Columns["N_WEEK_USEAMOUNT"].ColumnName = "周累计已支付金额";
                ds.Tables[4].Columns["N_GOL"].ColumnName = "流出率";
                ds.Tables[4].Columns["C_REMARK"].ColumnName = "备注";
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    ds.Tables[4].Rows.Add(dt.Rows[i].ItemArray);
                }
                ds.Tables[4].Columns.Remove(ds.Tables[4].Columns["N_ID3"]);
                ds.Tables[4].Columns.Remove(ds.Tables[4].Columns["N_PRO_ID"]);
                //ds.Tables[4].Columns.Remove(ds.Tables[4].Columns["N_TYPE"]);
                ds.Tables[4].Columns.Remove(ds.Tables[4].Columns["N_PLANAPP_ID"]);
                //ds.Tables[4].Columns.Remove(ds.Tables[4].Columns["N_CUSTOMER_ID"]);
                ds.Tables[4].Columns.Remove(ds.Tables[4].Columns["N_PROTYPE"]);
                //ds.Tables[4].Columns.Remove(ds.Tables[4].Columns["C_PRONAME"]);
                //ds.Tables[4].Columns.Remove(ds.Tables[4].Columns["N_NUM"]);
                //ds.Tables[4].Columns.Remove(ds.Tables[4].Columns["N_MONTHJEUSE"]);
                ////ds.Tables[4].Columns.Remove(ds.Tables[4].Columns["N_REAMOUNT"]);

                //ds.Tables[4].Columns.Remove(ds.Tables[4].Columns["C_AMOUT_TYPE"]);
                //ds.Tables[4].Columns.Remove(ds.Tables[4].Columns["C_AMOUT_USE"]);
                //ds.Tables[4].Columns.Remove(ds.Tables[4].Columns["N_ZBAMOUNT"]);
                //ds.Tables[4].Columns.Remove(ds.Tables[4].Columns["N_LASTMONTHJEUSE"]);
                //ds.Tables[4].Columns.Remove(ds.Tables[4].Columns["N_SPAMOUNT1"]);
                //ds.Tables[4].Columns.Remove(ds.Tables[4].Columns["N_SPAMOUNT2"]);
                //ds.Tables[4].Columns.Remove(ds.Tables[4].Columns["C_BANK"]);
            }
            if (type == "大修费用年明细表")
            {
                DataTable table = new DataTable();
                table = dt.Clone();
                table.TableName = "大修费用年明细表";
                ds.Tables.Add(table);

                ds.Tables[5].Columns["r"].ColumnName = "序号";
                ds.Tables[5].Columns["C_PRONAME"].ColumnName = "工程项目名称";
                ds.Tables[5].Columns["C_CUSTOMER_NAME"].ColumnName = "单位名称";
                //ds.Tables[5].Columns["C_AMOUT_TYPE"].ColumnName = "款项类别";
                //ds.Tables[5].Columns["C_AMOUT_USE"].ColumnName = "款项用途";
                ds.Tables[5].Columns["N_GZAMOUNT"].ColumnName = "账面应付余额";
                //ds.Tables[5].Columns["N_ZBAMOUNT"].ColumnName = "质保金";
                //ds.Tables[5].Columns["N_LASTMONTHJEUSE"].ColumnName = "上年止累计支付金额";
                ds.Tables[5].Columns["N_WEEK_AMOUNT"].ColumnName = "周累计审批金额";
                ds.Tables[5].Columns["N_WEEK_USEAMOUNT"].ColumnName = "周累计已支付金额";
                //ds.Tables[5].Columns["N_SPAMOUNT1"].ColumnName = "各单位审批金额";
                //ds.Tables[5].Columns["N_SPAMOUNT2"].ColumnName = "总部资金审批金额";
                ds.Tables[5].Columns["N_GOL"].ColumnName = "流出率";
                ds.Tables[5].Columns["C_REMARK"].ColumnName = "备注";
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    ds.Tables[5].Rows.Add(dt.Rows[i].ItemArray);
                }
                ds.Tables[5].Columns.Remove(ds.Tables[5].Columns["N_ID3"]);
                ds.Tables[5].Columns.Remove(ds.Tables[5].Columns["N_PRO_ID"]);
                //ds.Tables[5].Columns.Remove(ds.Tables[5].Columns["N_TYPE"]);
                ds.Tables[5].Columns.Remove(ds.Tables[5].Columns["N_PLANAPP_ID"]);
                //ds.Tables[5].Columns.Remove(ds.Tables[5].Columns["N_CUSTOMER_ID"]);
                ds.Tables[5].Columns.Remove(ds.Tables[5].Columns["N_PROTYPE"]);
                ////ds.Tables[5].Columns.Remove(ds.Tables[5].Columns["C_PRONAME"]);
                //ds.Tables[5].Columns.Remove(ds.Tables[5].Columns["N_NUM"]);
                //ds.Tables[5].Columns.Remove(ds.Tables[5].Columns["N_MONTHJEUSE"]);
                ////ds.Tables[5].Columns.Remove(ds.Tables[5].Columns["N_REAMOUNT"]);

                //ds.Tables[5].Columns.Remove(ds.Tables[5].Columns["C_AMOUT_TYPE"]);
                //ds.Tables[5].Columns.Remove(ds.Tables[5].Columns["C_AMOUT_USE"]);
                //ds.Tables[5].Columns.Remove(ds.Tables[5].Columns["N_ZBAMOUNT"]);
                //ds.Tables[5].Columns.Remove(ds.Tables[5].Columns["N_LASTMONTHJEUSE"]);
                //ds.Tables[5].Columns.Remove(ds.Tables[5].Columns["N_SPAMOUNT1"]);
                //ds.Tables[5].Columns.Remove(ds.Tables[5].Columns["N_SPAMOUNT2"]);
                //ds.Tables[5].Columns.Remove(ds.Tables[5].Columns["C_BANK"]);
            }
            if (type == "城市管网项目年明细表")
            {
                DataTable table = new DataTable();
                table = dt.Clone();
                table.TableName = "城市管网项目年明细表";
                ds.Tables.Add(table);

                ds.Tables[6].Columns["r"].ColumnName = "序号";
                ds.Tables[6].Columns["C_PRONAME"].ColumnName = "投资项目名称";
                ds.Tables[6].Columns["C_CUSTOMER_NAME"].ColumnName = "单位名称";
                //ds.Tables[6].Columns["C_AMOUT_TYPE"].ColumnName = "款项类别";
                //ds.Tables[6].Columns["C_AMOUT_USE"].ColumnName = "款项用途";
                ds.Tables[6].Columns["N_GZAMOUNT"].ColumnName = "账面应付余额";
                //ds.Tables[6].Columns["N_ZBAMOUNT"].ColumnName = "质保金";
                //ds.Tables[6].Columns["N_LASTMONTHJEUSE"].ColumnName = "上年止累计支付金额";
                ds.Tables[6].Columns["N_WEEK_AMOUNT"].ColumnName = "周累计审批金额";
                ds.Tables[6].Columns["N_WEEK_USEAMOUNT"].ColumnName = "周累计已支付金额";
                //ds.Tables[6].Columns["N_SPAMOUNT1"].ColumnName = "各单位审批金额";
                //ds.Tables[6].Columns["N_SPAMOUNT2"].ColumnName = "总部资金审批金额";
                ds.Tables[6].Columns["N_GOL"].ColumnName = "流出率";
                ds.Tables[6].Columns["C_REMARK"].ColumnName = "备注";
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    ds.Tables[6].Rows.Add(dt.Rows[i].ItemArray);
                }
                ds.Tables[6].Columns.Remove(ds.Tables[6].Columns["N_ID3"]);
                ds.Tables[6].Columns.Remove(ds.Tables[6].Columns["N_PRO_ID"]);
                //ds.Tables[6].Columns.Remove(ds.Tables[6].Columns["N_TYPE"]);
                ds.Tables[6].Columns.Remove(ds.Tables[6].Columns["N_PLANAPP_ID"]);
                //ds.Tables[6].Columns.Remove(ds.Tables[6].Columns["N_CUSTOMER_ID"]);
                ds.Tables[6].Columns.Remove(ds.Tables[6].Columns["N_PROTYPE"]);
                //ds.Tables[6].Columns.Remove(ds.Tables[6].Columns["N_NUM"]);
                //ds.Tables[6].Columns.Remove(ds.Tables[6].Columns["N_MONTHJEUSE"]);
                ////ds.Tables[6].Columns.Remove(ds.Tables[6].Columns["N_REAMOUNT"]);

                //ds.Tables[6].Columns.Remove(ds.Tables[6].Columns["C_AMOUT_TYPE"]);
                //ds.Tables[6].Columns.Remove(ds.Tables[6].Columns["C_AMOUT_USE"]);
                //ds.Tables[6].Columns.Remove(ds.Tables[6].Columns["N_ZBAMOUNT"]);
                //ds.Tables[6].Columns.Remove(ds.Tables[6].Columns["N_LASTMONTHJEUSE"]);
                //ds.Tables[6].Columns.Remove(ds.Tables[6].Columns["N_SPAMOUNT1"]);
                //ds.Tables[6].Columns.Remove(ds.Tables[6].Columns["N_SPAMOUNT2"]);
                //ds.Tables[6].Columns.Remove(ds.Tables[6].Columns["C_BANK"]);
            }
        }
    }
}